package com.ltmall.api.comm;

import com.ltmall.api.bean.Goods;
import com.ltmall.api.entity.JsonGoodsList;

import java.util.List;

public class FakeSalesVolumeUtil {

    public static void fakeByGoodsList(List<Goods> list) {
        if (list == null) {
            return;
        }

        for (Goods goods : list) {
            goods.setSellOut(fakeSalesVolume(goods.getGoodsID(), goods.getShopID(), goods.getSellOut()));
        }
    }

    public static void fakeByJsonGoodsList(List<JsonGoodsList> list) {
        if (list == null) {
            return;
        }

        for (JsonGoodsList goods : list) {
            goods.setSellNumber(fakeSalesVolume(goods.getGoodsID(), goods.getShopID(), goods.getSellNumber()));
        }
    }

    public static int fakeSalesVolume(int goodsId, int shopId, int realSalesVolume) {

        int a = numGet(goodsId, 1) * 1000 + numGet(goodsId, 2) * 100 + numGet(goodsId, 3) * 10 + numGet(goodsId, 4) * 1;
        int b = numGet(goodsId, 1) * 100 + numGet(goodsId, 2) * 10 + numGet(goodsId, 3) * 1;
        int c = shopId;

        int d = a * (numGet(c, 2) + 1);
        int e = b * (int) Math.pow(numGet(c, 1), 2);

        int f = d >> 2;
        int g = f & e;

        int h = g % 600 + 60 + realSalesVolume;

        return h;
    }

    public static int numGet(int num, int position) {
        return (num / ((int) Math.pow(10, position - 1))) % 10;
    }
}
